package com.banmao.algorithm.No101To200.No114;

public class Solution2 {

    public void flatten(TreeNode root) {

        if(root == null) return;

        flatten(root.left);
        flatten(root.right);

        // 递归到子节点
        // 将左节点放在右节点，原先的右节点放在原左节点的最后面
        TreeNode right = root.right;
        TreeNode left = root.left;
        if(left == null) {
            return;
        }
        root.right = left;
        root.left = null;
        while (left.right != null) {
            left = left.right;
        }
        left.right = right;

    }

}
